//
//  projectDetailVC.m
//  HappyStore
//
//  Created by 陈锋 on 16/5/18.
//  Copyright © 2016年 LLJ. All rights reserved.
//

#import "projectDetailVC.h"
#import "projectFirView.h"
#import "projectCell.h"
#import "commentVC.h"
#import "recommendViC.h"
#import "goveDetailVC.h"
#import "InvestmentProjectsView.h"
#import "WriteComment.h"
static NSString *projectcell = @"projectcell";

static float labelHeight;
static float sizeHeight;
static NSInteger count;
static NSInteger focusType;
@interface projectDetailVC ()<UITableViewDelegate,UITableViewDataSource,UIAlertViewDelegate>{
    NSInteger page;
}
@property (nonatomic, strong) UIScrollView *scrollView;
@property (strong, nonatomic) NSDictionary *dataDict; // 数据源
@property (strong, nonatomic) NSMutableArray *projectData; // 数据源
@property (strong, nonatomic) projectFirView *projectFir; // 中段界面
@property (strong, nonatomic) InvestmentProjectsView * investmentView;
@property (strong, nonatomic) UITableView *tableview;
@property (strong, nonatomic) UILabel * topTitle;

@property (strong, nonatomic) NSMutableArray *positionArr;
@property (strong, nonatomic) NSMutableArray *createTimeArr;
@property (strong, nonatomic) UIButton *cusBtn;
@property (strong, nonatomic) UILabel * descLabel;
@property (strong, nonatomic) UILabel * contentLabel;
@property (weak, nonatomic) IBOutlet UIButton *collectionBtn;

@property (strong, nonatomic) NSString *pinDaoStr;

@property (strong, nonatomic) recommendViC * recommendview;

@end

@implementation projectDetailVC
#pragma mark - 初始化
-(projectFirView *)projectFir{
    if (!_projectFir) {
        _projectFir = [[[NSBundle mainBundle]loadNibNamed:@"projectFirView" owner:self options:nil]lastObject];
    }
    return _projectFir;
}
-(InvestmentProjectsView *)investmentView{
    if (!_investmentView) {
        _investmentView = [[[NSBundle mainBundle]loadNibNamed:@"InvestmentProjectsView" owner:self options:nil]lastObject];
    }
    return _investmentView;
}
-(recommendViC *)recommendview{
    if (!_recommendview) {
        _recommendview = [[recommendViC alloc]init];
    }
    return _recommendview;
}
-(NSMutableArray *)projectData{
    if (!_projectData) {
        _projectData = [NSMutableArray array];
    }
    return _projectData;
}
-(NSMutableArray *)positionArr{
    if (!_positionArr) {
        _positionArr = [NSMutableArray array];
    }
    return _positionArr;
}
-(NSMutableArray *)createTimeArr{
    if (!_createTimeArr) {
        _createTimeArr = [NSMutableArray array];
    }
    return _createTimeArr;
}
-(NSDictionary *)dataDict{
    if (!_dataDict) {
        _dataDict = [NSDictionary dictionary];
    }
    return _dataDict;
}
- (UIScrollView *)scrollView
{
    if (!_scrollView) {
        self.scrollView = [[UIScrollView alloc] init];
    }
    return _scrollView;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:YES];
    
    count = 1;
    labelHeight = 200.0;
    
    // 请求数据
    [self sendRequest];
    
    // 加载评论
    [self sendProjectRequest];
    
    // 设置scrollview
    [self setupScrollView];
    
     [self.projectFir.jumpBtn addTarget:self action:@selector(goGove) forControlEvents:UIControlEventTouchUpInside];
    
    self.tabBarController.tabBar.hidden = YES;
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"白色背景"] forBarMetrics:UIBarMetricsDefault];
    //找出导航栏的下边的黑线
    UIImageView *navBarHairlineImageView = [NaviBarLine findHairlineImageViewUnder:self.navigationController.navigationBar];
    navBarHairlineImageView.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:247.0/255.0 green:247.0/255.0 blue:247.0/255.0 alpha:1];
    
    
    UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 190, 44)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.font = [UIFont systemFontOfSize:19];
    titleLabel.text = @"项目详情";
    titleLabel.textColor = RGB(45, 45, 45);
    titleLabel.textAlignment = NSTextAlignmentCenter;
    self.navigationItem.titleView = titleLabel;
    //设置返回按钮
    UIBarButtonItem *leftItem = [UIBarButtonItem itemWithTarget:self action:@selector(leftBarButtonItemClick) image:@"返回" highImage:@"返回"];
    self.navigationItem.leftBarButtonItem = leftItem;
    
    UIBarButtonItem *rightItem = [UIBarButtonItem itemWithTarget:self action:@selector(rightBarButtonItemClick) image:@"Share-Icon" highImage:@"Share-Icon"];
    self.navigationItem.rightBarButtonItem = rightItem;
    
    // 监听点击
    [self.recommendview.recommendView.sureBtn addTarget:self action:@selector(sureBtn) forControlEvents:UIControlEventTouchUpInside];

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updatePinlun:) name:@"updatePinlun" object:nil];
    //开启侧滑
    self.navigationController.interactivePopGestureRecognizer.delegate = (id)self;
    
    
    page = 1;
    
    self.tableview.scrollEnabled = NO;
}

- (void)updatePinlun: (NSNotification *)noti{
    NSDictionary *dic = [NSDictionary dictionaryWithDictionary:noti.userInfo];
    if ([dic[@"result"] integerValue] == 1) {
        page = 1;
        self.projectData = nil;
        [self sendProjectRequest];
    }
}

-(void)setupDownRefresh{

    // 设置回调（一旦进入刷新状态，就调用target的action，也就是调用self的loadMoreData方法）
    MJRefreshAutoGifFooter *footer = [MJRefreshAutoGifFooter footerWithRefreshingTarget:self refreshingAction:@selector(loadMoreData)];
    
    // 设置刷新图片
    UIImage *images = [UIImage imageNamed:@"mj_footer"];
    NSArray *refreshingImages = @[images];
    [footer setImages:refreshingImages forState:MJRefreshStateRefreshing];
    [footer setTitle:@"没有更多内容了" forState:MJRefreshStateRefreshing];
    footer.stateLabel.font = [UIFont systemFontOfSize:12.0f];
    footer.stateLabel.textColor = [UIColor colorWithWhite:0.6 alpha:1.0f];
    
    [footer setAutomaticallyRefresh:NO];
    
    self.scrollView.mj_footer = footer;
    

}
-(void)loadMoreData{
    page ++;
    [self sendProjectRequest];
}
-(void)goGove{
    
    goveDetailVC * goveVC = [[goveDetailVC alloc]init];
    goveVC.userId = _dataDict[@"userId"];
    goveVC.userType = _dataDict[@"userType"];
    [self.navigationController pushViewController:goveVC animated:YES];
    
}
-(void)sureBtn{
    
    if (self.recommendview.recommendView.nameTextField.text.length < 1 || self.recommendview.recommendView.phoneTextField.text.length < 1) {

        [self showSingleIconBubble:@"请完善内容"];

        
    }else{
        NSMutableDictionary * dic = [NSMutableDictionary dictionary];
        dic[@"resId"] = self.typeID;
        dic[@"userId"] = allConstMemberid;
        dic[@"token"] = allConstMemberToken;
        dic[@"type"] = @(3);
        dic[@"touchName"] = self.recommendview.recommendView.nameTextField.text;
        dic[@"touchWay"] = self.recommendview.recommendView.phoneTextField.text;
        
        [LSHttpTool sendHttpData:@"referralplatform_app_project.im.lensum" params:dic success:^(id responseObject) {
            [self.recommendview dismissViewControllerAnimated:YES completion:nil];
            
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"提示" message:@"平台引荐成功！工作人员将在三日之内给您答复！" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil];
            [alert show];
            
        } failure:^(NSError *error) {
            

            [self showSingleIconBubble:@"网络连接错误"];
            
        }];
        
    }
}

-(void)rightBarButtonItemClick{

//    [ShareMsg shareMsgBOOLType:YES titleStr:nil contentStr:nil urlStr:nil imageAry:nil];
}
-(void)leftBarButtonItemClick{
    [self.navigationController popViewControllerAnimated:YES];
}
- (void)setupScrollView
{
    self.scrollView.frame = CGRectMake(0, 64, screenW, screenH - 50 - 64);
    self.scrollView.showsHorizontalScrollIndicator = NO;
    self.scrollView.showsVerticalScrollIndicator = NO;
    self.scrollView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.scrollView];
}

-(void)setupTopTitle{
    UILabel *toptitle = [[UILabel alloc]init];
    toptitle.text = _dataDict[@"title"];
    toptitle.numberOfLines = 0;
    toptitle.backgroundColor = [UIColor whiteColor];
    toptitle.textColor = [UIColor blackColor];
    toptitle.textAlignment = NSTextAlignmentCenter;
    UIFont *font = [UIFont systemFontOfSize:20.0f];
    toptitle.font = font;
    CGSize constraint = CGSizeMake(screenW, 2000.0f);
    CGSize size = [toptitle.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    [toptitle setFrame:CGRectMake(0, 0, screenW, size.height + 40)];
    [_scrollView addSubview:toptitle];
    self.topTitle = toptitle;
    
}

-(void)setupProjectFir{

    self.projectFir.descLabel.text = _dataDict[@"description"];
    self.investmentView.detail.text = _dataDict[@"description"];
    
    NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:self.projectFir.descLabel.text];
    NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle1 setLineSpacing:8];
    [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [self.projectFir.descLabel.text length])];
    [self.projectFir.descLabel setAttributedText:attributedString1];
    [self.projectFir.descLabel sizeToFit];
    
    self.projectFir.descLabel.textAlignment = NSTextAlignmentLeft;
    UIFont *font = [UIFont fontWithName:@"Arial" size:14];
    self.projectFir.descLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    self.projectFir.descLabel.font = font;
    CGSize constraint = CGSizeMake(screenW, 9000.0f);
    CGSize size = [self.projectFir.descLabel.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    sizeHeight = size.height;
        
    if (self.userId) {
        
        NSMutableAttributedString * attributedString1 = [[NSMutableAttributedString alloc] initWithString:self.investmentView.detail.text];
        NSMutableParagraphStyle * paragraphStyle1 = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle1 setLineSpacing:8];
        [attributedString1 addAttribute:NSParagraphStyleAttributeName value:paragraphStyle1 range:NSMakeRange(0, [self.investmentView.detail.text length])];
        [self.investmentView.detail setAttributedText:attributedString1];
        [self.investmentView.detail sizeToFit];
        
        self.investmentView.detail.textAlignment = NSTextAlignmentLeft;
        UIFont *font = [UIFont fontWithName:@"Arial" size:14];
        self.investmentView.detail.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
        self.investmentView.detail.font = font;
        CGSize constraint = CGSizeMake(screenW, 9000.0f);
        CGSize size = [self.investmentView.detail.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
        
        self.investmentView.frame = CGRectMake(0, self.topTitle.height + 2, screenW, self.investmentView.detail.y + self.investmentView.detail.height + 60);

        self.projectFir.downBtn.backgroundColor = [UIColor whiteColor];
        [self.investmentView.down addTarget:self action:@selector(donwBtn:) forControlEvents:UIControlEventTouchUpInside];

        self.investmentView.areaAddress.text = _dataDict[@"address"];
        self.investmentView.direction.text = _dataDict[@"industry"];
        float floatValue = [_dataDict[@"investment"] floatValue];
        self.investmentView.price.text = [CustomExcetion comperNumber:@(floatValue)];

        [self.scrollView addSubview:self.investmentView];
        
        
        [self setupTableView];
        self.scrollView.contentSize = CGSizeMake(0, self.topTitle.height + self.investmentView.height + 100);
        
    }else{
        
//        [self.projectFir.descLabel setFrame:CGRectMake(8, self.projectFir.address.y + 60, self.view.width - 16, labelHeight)];
        
//        self.descLabel = self.projectFir.descLabel;
//        [self.projectFir addSubview:self.projectFir.descLabel];
        
    self.projectFir.frame = CGRectMake(0, self.topTitle.height + 2, screenW, self.projectFir.descLabel.y + self.projectFir.descLabel.height + 40);
        
//        self.cusBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, self.projectFir.height - 20 , self.view.width, 40)];
        [self.projectFir.downBtn addTarget:self action:@selector(donwBtn:) forControlEvents:UIControlEventTouchUpInside];

        
        // 设置圆形头像
        [self.projectFir.headPhoto.layer setCornerRadius:(self.projectFir.headPhoto.frame.size.height/2)];
        [self.projectFir.headPhoto.layer setMasksToBounds:YES];
        [self.projectFir.headPhoto setContentMode:UIViewContentModeScaleAspectFill];
        [self.projectFir.headPhoto setClipsToBounds:YES];
        self.projectFir.headPhoto.layer.shadowColor = [UIColor blackColor].CGColor;
        self.projectFir.headPhoto.layer.shadowOffset = CGSizeMake(4, 4);
        self.projectFir.headPhoto.layer.shadowOpacity = 0.5;
        self.projectFir.headPhoto.layer.shadowRadius = 2.0;
        self.projectFir.headPhoto.userInteractionEnabled = YES;
        [self.projectFir.headPhoto sd_setImageWithURL:_dataDict[@"headPhoto"] placeholderImage:[UIImage imageNamed:@"20100403114758394_4147"]];
        self.projectFir.userName.text = _dataDict[@"userName"];
        self.projectFir.paymentMechanism.text = _dataDict[@"paymentMechanism"];
        self.projectFir.projectLevel.text = _dataDict[@"projectLevel"];
        self.projectFir.implementationStage.text = _dataDict[@"implementationStage"];
        self.projectFir.industry.text = _dataDict[@"industry"];
        self.projectFir.address.text = _dataDict[@"address"];
        self.projectFir.works.text = _dataDict[@"works"];
        //会员图标
        self.projectFir.vipImage.image = [UsedTool setVipimage:_dataDict[@"vipLevel"]];
        float floatValue = [_dataDict[@"investment"] floatValue];

        self.projectFir.investment.text = [CustomExcetion comperNumber:@(floatValue)];
        NSString *str2 = [_dataDict[@"createTime"] substringToIndex:10];
        self.projectFir.creatTime.text = str2;

        [self.scrollView addSubview:self.projectFir];
        
        
        [self setupTableView];
        self.scrollView.contentSize = CGSizeMake(0, self.topTitle.height + self.projectFir.height + 100);

    
    }


    
}

-(void)donwBtn:(UIButton *)btn{
    
    btn.selected = !btn.selected;
    count ++;
    [self.projectFir removeFromSuperview];
    [self.investmentView removeFromSuperview];
    [self.tableview removeFromSuperview];
    if (count %2 == 0) {
        self.investmentView.detail.numberOfLines = 0;
        self.projectFir.descLabel.numberOfLines = 0;
    }else{
        self.investmentView.detail.numberOfLines = 3;
        self.projectFir.descLabel.numberOfLines = 3;
    }
    
    [self setupProjectFir];
    
}


-(void)setupTableView{
    UITableView *tableview = [[UITableView alloc]init];
    tableview.x = 0 ;
    if (self.userId) {
        
        tableview.y = self.investmentView.y + self.investmentView.height + 20;
        
    }else{
        
        tableview.y = self.projectFir.y + self.projectFir.height  + 50;
    
    }

    tableview.width = screenW;
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.showsVerticalScrollIndicator = NO;
    tableview.showsHorizontalScrollIndicator = NO;
    tableview.rowHeight = 71;
    [self.scrollView addSubview:tableview];
    
    self.tableview = tableview;
    
    // 集成下拉加载更多
    [self setupDownRefresh];
    
    [self.tableview reloadData];
    
}


#pragma mark - 控件方法
// 平台引荐
- (IBAction)recommendBtn:(UIButton *)sender {
    if (allConstMemberid) {
        
    self.recommendview.modalPresentationStyle=UIModalPresentationOverCurrentContext;
    [self presentViewController:self.recommendview animated:YES completion:nil];
        
    }else{

        [self showErrorWithTitle:@"请先登录!" autoCloseTime:2];
    }

}
// 分享
- (IBAction)shareBtn:(UIButton *)sender {
    [ShareMsg shareMsgBOOLType:YES titleStr:nil contentStr:nil urlStr:nil imageAry:nil];
}
// 评论
- (IBAction)commentBtn:(UIButton *)sender {
    //    if (allConstMemberid) {
    //
    //    commentVC * comtVC = [[commentVC alloc]init];
    //
    //    comtVC.resId = self.typeID;
    //    [self.navigationController pushViewController:comtVC animated:YES];
    //
    //    }else{

    //        [MRProgressOverlayView showErrorWithStatus:@"请先登录!"];

    //    }
    if (allConstMemberid) {
        WriteComment *writeView = [[WriteComment alloc] init];
        [writeView setFrame:CGRectMake(0, self.view.frame.size.height - 48, screenW, 48)];
        writeView.resId = self.typeID;
        writeView.urlStr = @"commentPppProject_app_ppp.im.lensum";
        [self.view addSubview:writeView];
        
    }else{
        [self showErrorWithTitle:@"请先登录" autoCloseTime:2];

    }

}
// 收藏
- (IBAction)collectionBtn:(UIButton *)sender {
    
    if (allConstMemberid) {
        
    
    sender.selected = !sender.selected;
    
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    dic[@"userId"] = allConstMemberid;
    dic[@"token"] = allConstMemberToken;
    dic[@"resId"] = self.typeID;
    
    if (self.collectionBtn.selected == NO) {
        
        focusType =2;
        
    }else if (self.collectionBtn.selected == YES){
    
        focusType = 1;
    }
    dic[@"type"] = @(focusType);
    
    [LSHttpTool sendHttpData:@"focusPppProject_app_ppp.im.lensum" params:dic success:^(id responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];


        [self showRightWithTitle:dicInfo[@"msg"] autoCloseTime:2];


//        [MRProgressOverlayView showSuccessWithStatus:dicInfo[@"msg"]];


        
    } failure:^(NSError *error) {

        [self showSingleIconBubble:@"网络连接错误"];
        
    }];
        
    }else{

        [self showErrorWithTitle:@"请先登录!" autoCloseTime:2];
    }
}

#pragma mark - tableview datasource
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _projectData.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//    NSLog(@"-----------------%@",self.positionArr);
    // 注册
    UINib * nib = [UINib nibWithNibName:@"projectCell" bundle:nil];
    [self.tableview registerNib:nib forCellReuseIdentifier:projectcell];
    
    projectCell * cell = [self.tableview dequeueReusableCellWithIdentifier:projectcell];
    cell.lineview.hidden = YES;
    if (!cell) {
        cell = [[projectCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:projectcell];
    }
//    cell.posiTion.text = self.positionArr[indexPath.row];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.accessoryType = UITableViewCellAccessoryNone;
    
    
    NSDictionary *dict = _projectData[indexPath.row];
    cell.posiTion.text = dict[@"posiTion"];
    [cell.headPhoto sd_setImageWithURL:dict[@"headPhoto"] placeholderImage:[UIImage imageNamed:@"20100403114758394_4147"]];
    
    cell.headPhoto.layer.masksToBounds = YES;
    cell.headPhoto.layer.cornerRadius = 20.0f;
    
    cell.commentUsername.textColor = [UIColor colorWithRed:23.0/255.0 green:176.0/255.0 blue:217.0/255.0 alpha:1];
    
    if ([dict[@"commentUsername"] isEqualToString:@"null"] || [dict[@"commentUsername"] isEqualToString:@""]) {
        cell.commentUsername.text = dict[@"commentAccount"];
    }else{
    cell.commentUsername.text = dict[@"commentUsername"];
    }
    
    NSDate *date = [CustomExcetion dateFromString:dict[@"createTime"]];
    cell.createTime.text = [CustomExcetion prettyDateWithReference:date];
    
    cell.commentLabel.text = dict[@"content"];

    if ([dict[@"userType"] isEqualToString:@"3"]) {
        cell.posiTion.text = @"";
        
        if ([dict[@"goveUserName"] isEqualToString:@"null"]) {
            cell.companyUserName.text = @"";
        }else{
            cell.companyUserName.text = dict[@"goveUserName"];
        }
    }else if ([dict[@"userType"] isEqualToString:@"2"]){
        
        if ([dict[@"goveUserName"] isEqualToString:@"null"] && [dict[@"companyUserName"] isEqualToString:@"null"]) {
            
            cell.companyUserName.text = @"";
            
        }else if ([dict[@"goveUserName"] isEqualToString:@"null"]){
            
            cell.companyUserName.text = dict[@"companyUserName"];
            
        }else if ([dict[@"companyUserName"] isEqualToString:@"null"]){
            
            cell.companyUserName.text = dict[@"goveUserName"];
            
        }
        
    }

    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    projectCell *cell = [self tableView:self.tableview cellForRowAtIndexPath:indexPath];
    
       cell.commentLabel.numberOfLines = 0;
    
        cell.commentLabel.textAlignment = NSTextAlignmentLeft;
        UIFont *font = [UIFont fontWithName:@"Arial" size:12];
        cell.commentLabel.textColor = [UIColor blackColor];
        cell.commentLabel.font = font;
        CGSize constraint = CGSizeMake(cell.width - 53, 9000.0f);
        CGSize size = [cell.commentLabel.text sizeWithFont:font constrainedToSize:constraint lineBreakMode:UILineBreakModeWordWrap];
    
        [cell.commentLabel setFrame:CGRectMake(53, 45, cell.width - 53, size.height)];

        //设置cell自适应高度
        CGRect cellFrame = [cell frame];
        cellFrame.origin = CGPointMake(0, 0);
        CGFloat totalHeight = cellFrame.size.height+cell.commentLabel.height;
        cellFrame.size.height = totalHeight;
        [cell setFrame:cellFrame];
    
    self.tableview.height = self.tableview.contentSize.height;
    
    if (self.userId) {
        self.scrollView.contentSize = CGSizeMake(0, self.tableview.height + self.topTitle.height + self.investmentView.height + 50);
        
    }else{
        
    self.scrollView.contentSize = CGSizeMake( 0, self.tableview.height + self.topTitle.height + self.projectFir.height + 120);
    }
    return cell.frame.size.height;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 1;
}
#pragma mark - alert delegete
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex == 0) {
  
        [self.recommendview dismissViewControllerAnimated:YES completion:nil];
        
            }
   
        [self viewWillAppear:YES];
 
}

#pragma mark - 请求数据
-(void)sendRequest{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    dic[@"id"] = self.typeID;
    dic[@"userId"] = self.userId;
    
    [LSHttpTool sendHttpData:@"getPppProjectDetail_app_ppp.im" params:dic success:^(id responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        _dataDict = dicInfo[@"data"];
        
        if ([_dataDict[@"isfocus"] isEqualToString:@"是"]) {
            
            self.collectionBtn.selected = YES;
            
        }else if ([_dataDict[@"isfocus"] isEqualToString:@"否"]){
            
            self.collectionBtn.selected = NO;
        }
        
        // 设置toptitle
        [self setupTopTitle];
        
        //设置基础数据
        [self setupProjectFir];
        
    } failure:^(NSError *error) {

       [self showSingleIconBubble:@"网络连接错误"];
        
    }];
}

-(void)sendProjectRequest{
    NSMutableDictionary * dic = [NSMutableDictionary dictionary];
    dic[@"page"] = @(page);
    dic[@"id"] = self.typeID;
    
    [LSHttpTool sendHttpData:@"getCommentList_app_ppp.im" params:dic success:^(id responseObject) {
        NSDictionary *dicInfo = [NSDictionary dictionaryWithDictionary:responseObject];
        
        NSArray * arr = dicInfo[@"data"];
        
        NSDictionary *dataDic = [NSDictionary dictionary];
        
        dataDic = dicInfo[@"data"];
        if (page == 1) {
                
                _projectData = nil;
                _projectData = dicInfo[@"data"];
                for (NSDictionary * dict in dicInfo[@"data"]) {
                    
                    [self.createTimeArr addObject:dict[@"createTime"]];
                }
                for (NSDictionary * dict in dicInfo[@"data"]) {
                    
                    [self.positionArr addObject:dict[@"posiTion"]];
                }
                
                if (_projectData.count == 10) {
                    
                    self.scrollView.mj_footer.hidden = NO;
                    
                }else{
                
                    self.scrollView.mj_footer.hidden = YES;
                
                }
                [self.tableview reloadData];
                
            }else if(page != 1 && arr.count > 0){
                NSArray *arr = dicInfo[@"data"];
                NSMutableArray * mtArr = [NSMutableArray array];
                for (NSDictionary * dict in _projectData) {
                    [mtArr addObject:dict];
                }
                for (NSDictionary * dict in arr) {
                    [mtArr addObject:dict];
                }
                _projectData = nil;
                _projectData = mtArr;
                
                [self.tableview reloadData];
                
                if (mtArr.count == 10) {
                    
                    self.scrollView.mj_footer.hidden = NO;
                    
                }else{
                    
                    self.scrollView.mj_footer.hidden = YES;
                    
                }
            }


            // 设置tableview
//            [self setupTableView];
        
            [self.tableview reloadData];
  
        [self.tableview.mj_footer endRefreshing];
        
    } failure:^(NSError *error) {
        [self.tableview.mj_footer endRefreshing];

        [self showSingleIconBubble:@"未搜索到内容"];

    }];
}

-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:YES];
    [self.navigationController.navigationBar setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
    self.projectFir = nil;
    self.tableview = nil;
}
@end
